
testOptimizations([
	['if (call1()) call2();',
		'call1() && call2();'],
	
	['if (call1() && call3()) call2();',
		'call1() && call3() && call2();'],
	
	['if (call1() || call3()) call2();',
		'(call1() || call3()) && call2();'],
	
	['if (call1(), call3()) call2();',
		'(call1(), call3()) && call2();'],
	
	['if (call1()) call2(); else call3();',
		'call1() ? call2() : call3();'],
	
	['if (call1()) call2(); else call3();',
		'call1() ? call2() : call3();'],
	
	['if (true) call2(); else call3();',
		'call2();'],
	
	['if (false) call2(); else call3();',
		'call3();'],
	
	// remove 'else' branch when empty
	['if (var1) call1(); else {}',
		'var1 && call1();'],
	
	// this combines the above into something a bit more complex
	['if (a) if (b) c(); else d();',
		'a && (b ? c() : d());'],
	
	// join 2 ifs
	['if (a) if (b) throw 1;',
		'if (a && b) throw 1;'],
	
	// join 3 ifs
	['if (a) if (b) if (c) throw 1;',
		'if (a && b && c) throw 1;'],
	
	// can't join 2 ifs if the second has an else branch
	['if (a) if (b) throw 1; else d();',
		'if (a) if (b) throw 1; else d();'],
	
	// merge two branches which both use throw
	['if (a) throw b; else throw c;',
		'throw a ? b : c;'],
	
	// merge two branches which both use return
	['function d() { if (a) return b; else return c; }',
		'function d() { return a ? b : c; }'],
	
	// merge two branches which both use default
	['if (a) default xml namespace = b; else default xml namespace = c;',
		'default xml namespace = a ? b : c;'],
	
	// when the then-block is empty and there is no else-block or it is also empty, remove the if
	['if (a()) {};',
		'a();'],
	
	['if (a()) {} else {};',
		'a();'],
	
	// when the then-block is empty and there is an else-block, reverse the condition and remove the if
	['if (a) {} else throw 2;',
		'if (!a) throw 2;'],
	
	// if the `then` branch is a statement (return, throw, default) and there is not `else` branch but the `if` statement is followed by the same type of statement, merge the statements
	['if (a) throw b; throw c;',
		'throw a ? b : c;'],
	
	['if (a) default xml namespace = b; default xml namespace = c;',
		'default xml namespace = a ? b : c;'],
	
	['function x() { if (a) return b; return c; }',
		'function x() { return a ? b : c; }'],
	
	['if (a) { 2; throw b; } throw c;',
		'throw a ? b : c;'],
	
	['function a() { var b = false; do { if (!b) b = c(); else throw 1; } while (true); };',
		'function a() { var b; b = false; do if (!b) b = c(); else throw 1; while (true); }']
]);
